/**
 *  功能: 测试类公共方法
 *  created by Harry 2016-12-20
 */
public class TestUtils
{   


    public static Integer plus(Integer a , Integer b ){

        Integer c =  a+b;
        return c ;

    }
    /**
        创建用户
     */
    public static void createUsers(){
        Id ldcProfile = [Select Id From Profile Where Name ='系统管理员' or Name='System Administrator'].Id;
        Id engProfile = [Select Id From Profile Where Name ='工程部工程师'].Id;
        User u1 = new User( Alias = 'samLdc1', 
                         Email = 'ldc@test.com.maike',
                         Emailencodingkey = 'UTF-8', 
                         Lastname = '用户1', 
                         Languagelocalekey = 'en_US',
                         Localesidkey = 'en_US', 
                         Profileid = ldcProfile, 
                         Country = 'United States',
                         IsActive = true,
                         SubCompany__c='四川省迈克实业有限公司',
                         UserDepartment__c='客户服务中心(工程部)',
                         Timezonesidkey = 'America/Los_Angeles', 
                         EmployeeNumber = '123451',
                         Username = 'Matldc1@test.com.maike' );
        
        User u2 = new User( Alias = 'samLdc2', 
                Email = 'ldc@test.com.maike',
                Emailencodingkey = 'UTF-8', 
                Lastname = '用户2', 
                Languagelocalekey = 'en_US',
                Localesidkey = 'en_US', 
                Profileid = ldcProfile, 
                Country = 'United States',
                IsActive = true,
                UserDepartment__c='客户服务中心(产品培训部)',
                Timezonesidkey = 'America/Los_Angeles', 
                EmployeeNumber = '123452',
                Username = 'Matldc2@test.com.maike' );
        User u3 = new User( Alias = 'samLdc3', 
                Email = 'ldc@test.com.maike',
                Emailencodingkey = 'UTF-8', 
                Lastname = '用户3', 
                Languagelocalekey = 'en_US',
                Localesidkey = 'en_US', 
                Profileid = ldcProfile, 
                Country = 'United States',
                IsActive = true,
                UserDepartment__c='客户服务中心(产品培训部)',
                Timezonesidkey = 'America/Los_Angeles', 
                EmployeeNumber = '123453',
                Username = 'Matldc3@test.com.maike' );
        User u4 = new User( Alias = 'samLdc4', 
                Email = 'ldc@test.com.maike',
                Emailencodingkey = 'UTF-8', 
                Lastname = '工程师1', 
                Languagelocalekey = 'en_US',
                Localesidkey = 'en_US', 
                Profileid = engProfile, 
                Country = 'United States',
                IsActive = true,
                UserDepartment__c='客户服务中心(工程部)',
                Timezonesidkey = 'America/Los_Angeles', 
                EmployeeNumber = '123454',
                Username = 'Matldc4@test.com.maike' );
        
        insert new List<User>{u1,u2,u3,u4};
    }
    public static Account createAccount()
    {
        RecordType rt = [select Id from RecordType where SObjectType = 'Account' and DeveloperName = 'TerminalCustomer'];
        /**
            创建客户
        */
        Account a  = new Account();
        a.Name  = '测试客户';
        a.Status__c = '审核通过';
        a.RecordTypeId = rt.Id;
        //a.MedicineManageLicense__c = '有';
        a.FinancialInfoQuality__c = '审计报告无保留意见';
        a.Iskeynote__c = false;
        a.BuyerContribution__c = '年销售占比80%以上客户中排名前50%';
        a.EnterpriseType__c = '国营';
        a.Postcode__c = '450000';
        a.Category__c = '综合医院';
        a.BedNumAuthorize__c = 100;
        //a.Fax = '1';
        a.SecondCategoryDetail__c = '6807胸腔心血管外科手术器械';
        a.ThirdCategoryDetail__c = '6828医用磁共振设备';
        a.QSCertificateEndDate__c = Date.newInstance(2016, 12, 19);
        a.GSPManageScale__c = '1';
        //a.Note__c = '1';
        a.CooperationHistoryCredibility__c = '年超期申请≤5次';
        a.FlowRatio__c = '≥180%';
        //a.InstrumentRange__c = '1';
        //a.AccName__c = '经销商1219';
        //a.SecondRecordNo__c = '1';
        //a.Medicine__c = 'HIV';
        //a.LastYearTax__c = 1.0;
        a.LastYearRevenue__c = 1.0;
        //a.InstrumentName__c = '11111';
        a.CusType__c = '经营企业';
        //a.RealDegree__c = '1';
        a.Address__c = '武侯区155号';
        //a.CreditLimitControl__c = true;
        a.CooperationRelationship__c = '≥30%';
        //a.IsAreaDealer__c = true;
        a.OperationCashFlow__c = '正值以上';
        //a.SecondRecordEndDate__c = Date.newInstance(2016, 12, 19);
        a.AssetLiabilityRatio__c = '≤55%';
        //a.GSPMedicineQualityManageRul__c = 'GSP【药品经营质量管理规范认证】';
        a.QSCertificate__c = '医疗器械';
        //a.MedicineManageLicenseManageScale__c = '药品经营许可证经营范围';
        a.Artificial__c = '法人';
        a.Company__c = '关联公司';
        a.BusinessLicenseEndDate__c = Date.newInstance(2016, 12, 19);
        a.IncomeIncreaseRate__c = '高于公司年销售增长率';
        a.Area__c = '西南区';
        a.Website = 'www.abc.com';
        //a.MedicineDevice__c = '6801基础外科手术器械';
        //a.ExtID__c = '经销商1219';
        a.Phone = '8002345';
        a.TaxRegisterLicense__c = '1234';
        a.RegisterAmount__c = 100.0;
        a.InstrumentLicenseNum__c = '1';
        a.AnnualSales__c = '≥5000万';
        a.InstrumentLicenseEndDate__c = Date.newInstance(2016, 12, 19);
        //a.IVDCategory__c = '体外诊断经营类别';
        //a.CreditDeadlineControl__c = true;
        a.IndustryFinancialCredibility__c = '无失信记录';
        a.CustomerAttribute__c = '公立医疗机构';
        a.Level__c = '一级医院';
        a.SpecialDepart__c = '内科_呼吸内科; 内科_神经内科';
        return a;
    }

    public static Account createDealer() {
        RecordType rt = [select Id from RecordType where SObjectType = 'Account' and DeveloperName = 'Dealer'];
        Account a  = new Account();
        a.Name  = '测试经销商'+Math.random();
        a.Status__c = '审核通过';
        a.RecordTypeId = rt.Id;

        return a;
    }
    /**
        创建国家
    */
    public static Country__c createCountry()
    {
        Country__c c  = new Country__c();
        c.Name = '中国';
        c.Population__c = '13亿';
        return c;
    }
    /**
        创建
    */
    // public static CharacteristicMedicalMarket__c createCharacteristicMedicalMarket(){
    //     CharacteristicMedicalMarket__c m  = new CharacteristicMedicalMarket__c();
    //     //m.Country__c = 'a0hp0000002W26l';
    //     //m.TotalHospital__c  = 123.0;
    //     //m.TotalClinic__c  = 1234.0;
       
    //     m.Name  = '医疗市场Mark';
    //     return m;
    // }
    /**
        创建医疗整体市场
    */
    public static MedicalGrade__c createMedicalGrade(){
        MedicalGrade__c g = new MedicalGrade__c();
        //g.MedicalMarkter__c = 'a0ip0000001KSHNAA4';
        //g.Name = '等级一';
        g.Feature__c = '1234';
        g.Amount__c = 50.0;
        return  g;
    }
    /**
        创建业务机会
    */
    public static Opportunity createOpportunity(){
        Account dealer = createDealer();
        insert dealer;

        Opportunity opp = new Opportunity();
        opp.Name = '业务机会A';
        opp.StageName = '意向';
        opp.Department__c = '检验科';
        opp.CloseDate = Date.newInstance(2017, 3, 13);
        opp.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('CustomerOpportunity','Opportunity');
        opp.ExecuteCompany__c = dealer.Id;
        return opp;
    }
    /**
        创建联系人
    */
    public static Contact createContact(){
        Contact c = new Contact();
        c.LastName = '测试联系人';
        c.Post__c = '科长/主任'; 
        c.Departments__c = '采购科/采供部';
        return c;
    }

    /**
        创建对象    产品试剂
    */
    public static Product__c createProduct(){
        Product__c product = new Product__c();
        product.Category1__c='临检'; 
        product.Tax__c=17.0; 
        product.Name='尿有形成份检测稀释液UPS'; 
        product.Category3__c='SYSMEX-XN专用'; 
        product.Category4__c='试剂'; 
        product.Category2__c='尿液'; 
        product.Unit__c='盒'; 
        product.SerialNo__c='ZG801009'; 
        product.Brand__c='济南希森美康'; 
        product.Spec__c='1L*2'; 
        product.Category0__c='试剂';
        product.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('CompetitorProduct','Product__c');
        // product.Model__c='UPS';
        return product;
    }

    /**
        创建对象    产品仪器
    */
    public static Product__c createInst(){
        Product__c product = new Product__c();
        product.Category1__c='临检'; 
        product.Name='全自动尿有形成份分析仪'; 
        product.Category3__c='SYSMEX-XN专用'; 
        product.Category4__c='尿液分析仪'; 
        product.Category2__c='尿液'; 
        product.Unit__c='台'; 
        product.SerialNo__c='UF-1000i'; 
        product.Brand__c='济南希森美康'; 
        product.Category0__c='仪器';
        product.RecordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('CompetitorProduct','Product__c');
        // product.Model__c='Mdele1';
        product.NormalRequirement1__c = 'test';
        product.NormalRequirement2__c = 'test';
        product.NormalRequirement3__c = 'test';
        product.NormalRequirement4__c = 'test';
        product.NormalRequirement5__c = 'test';
        product.NormalRequirement6__c = 'test';
        product.NormalRequirement7__c = 'test';
        product.NormalRequirement8__c = 'test';
        product.NormalRequirement9__c = 'test';
        product.NormalRequirement10__c = 'test';
        return product;
    }

    /**
        创建对象    价格
    */
    public static Price__c createPrice(){
        Price__c price = new Price__c();
        price.Company__c = '四川省迈克实业有限公司';
        price.MarketPrice__c = 10000;
        price.HospitalManagerPrice__c = 8000;
        price.InvoiceDealerPrice__c = 7000;
        price.AreaDealerPrice__c = 6000;
        price.HospitalBottomPrice__c = 5000;
        price.InstCost__c = 4000;
        price.RepairCost__c = 3000;
        return price;
    }

    /**
        创建对象    省
    */
    public static Province__c createProvince(){
        Province__c province = new Province__c();
        province.Area__c='西南区';
        province.Name='四川省';
        return province;
    }

    /**
        创建对象 地级市
    */
    public static City__c createCity(){
        City__c city = new City__c();
        city.Name='成都市';
        return city;
    }

    /**
        创建对象    区/县
    */
    public static District__c createDistrict(){
        District__c district = new District__c();
        district.Name='武侯区';
        return district;
    }

    /**
        创建对象    IVD各产品线市场
    */
    public static IVDProductLineMarket__c createIVDProductLineMarket(){
        IVDProductLineMarket__c ivd = new IVDProductLineMarket__c();
        //ivd.Product__c='3'; 
        //ivd.Feature__c='123'; 
        //ivd.Name='生化线'; 
        ivd.MarketCapacity__c=1000000.0; 
        //ivd.Model__c='123'; 
        return ivd;
    }

    /**
        创建对象    IVD整体市场
    */
    public static IVDWholeMarket__c createIVDWholeMarket(){
        IVDWholeMarket__c ivd = new IVDWholeMarket__c();
        //ivd.Name='IVD市场';
        //ivd.Clinicallaboratory__c=1;
        return ivd;
    }

    /**
        创建对象    意向产品
    */
    public static IntentProduct__c createIntentProduct(){
        IntentProduct__c ip = new IntentProduct__c();
        ip.Name = '加斯戴克血球DH510';
        ip.SalesPrice__c = 0.0;
        // ip.Category0__c = '仪器';
        // ip.Category2__c = '血球';
        ip.Quantity__c = 1.0;
        ip.Brand__c = '加斯戴克';
        // ip.Category1__c = '临检';
        ip.UnitPrice__c = 0.0;
        return ip;
    }
    /**
        创建对象    型号
     */
    // public static Model__c createModel(){
    //     Model__c m = new Model__c();
    //     m.Name = '测试用型号';
    //     m.ExtId__c = '001p000000IavroAAB';
    //     return m;
    // }
    /**
        创建对象    仪器
     */
    public static Equipment__c createEquipment(){
        Equipment__c equip = new Equipment__c();
        //equip.Name = '测试用仪器名称';
        return equip;
    }
    /**
        创建自定义设置对象
     */
    public static smsApi__c createSmsApic(){
        smsApi__c setting = new smsApi__c();
        setting.Name = 'SMS_Setting';
        setting.LoginName__c = 'mk_sw';
        setting.Password__c = 'gfgs2002';
        setting.URL__c = 'https://api.ums86.com:9600/sms/Api/Send.do?&f=1';
        setting.SpCode__c = '238039';
        setting.reply_URL__c = 'https://api.ums86.com:9600/sms/Api/reply.do';
        setting.replyConfirm_URL__c = 'https://api.ums86.com:9600/sms/Api/replyConfirm.do';
        return setting;
    }
    public static WeiXinAPI__c createWeiXinAPI(){
        WeiXinAPI__c setting = new WeiXinAPI__c();
        setting.Name = 'Weibo_Setting';
        setting.URL__c = 'https://xxxxx/ws/Maike/delivery';
        setting.Security__c = 'shwmeimob';
        return setting;
    }
    /**
        创建部门
     */
    public static Department__c createDepartment(){
        Department__c dept = new Department__c();
        dept.Name = '检验科';
        dept.LastYearRevenue__c = 500000;
        dept.LowProfNum__c = 20;
        dept.HighProfNum__c = 4;
        dept.MidProfNum__c = 6;
        dept.PersonNum__c = 30;
        return dept;
    }
    /**
        创建合同
     */
    public static Contract__c createContract(){
        Contract__c con = new Contract__c();
        con.StartDate__c = Date.valueOf('2017-01-01');
        con.EndDate__c = Date.valueOf('2018-01-01');
        con.ContractAmount__c = 458009;
        con.ContractSource__c = '草拟合同';
        //con.CompanyName__c = '四川省迈克实业有限公司';
        return con;
    }
    /**
        创建订单
     */
    public static Order__c createOrder(){
        Order__c ord = new Order__c();
        ord.NCsale_hid__c='1';
        ord.NCcorpcode__c = '001';
        ord.Order_Date__c = Date.valueOf('2017-01-02');
        ord.NCcorpname__c = '四川省迈克实业有限公司';
        ord.NC_Product_Line__c = '试剂';
        ord.NC_Billing_Type__c = '发票';
        ord.NCcustcode__c = 'A001';
        ord.NCcustname__c = '成都市第一人民医院';
        ord.Name = 'OD001001001';
        return ord;
    }
    /**
        创建工单
     */
    public static WorkOrder__c createWorkOrder(){
        String recordTypeId = Utils.getRecordTypeIdByDevNameAndObjName('InstallationOrder', 'WorkOrder__c');
        WorkOrder__c wo = new WorkOrder__c();
        wo.RecordTypeId = recordTypeId;
        return wo;
    }
    /**
        创建应收对账单临时表数据
     */
    public static void createReceivableTemp(){
        Receivable_Temp__c rc = new Receivable_Temp__c();
        rc.corpcode__c = '003';//公司编码
        rc.dbilldate__c = Date.valueOf('2017-02-15');//单据日期
        rc.billcode__c = 'NO.54217855';//单据编号
        rc.xydqr__c = Date.valueOf('2015-02-28');//到期日
        rc.zy__c = '摘要3';//摘要
        rc.custcode__c = 'A003';//客户编码
        rc.custname__c = 'A003';//客户名称
        rc.deptcode__c = 'D003';//部门编号
        rc.deptname__c = 'D003';//部门名称
        rc.jfbbje__c = 255000;//本期应收
        rc.dfbbje__c = 24000;//本期收回
        rc.bbye__c = 210000;//单据余额
        rc.ye__c = 158750;//余额
        rc.fph__c = 'NO.124589';//发票号
        rc.km__c = 'K003';//科目编号
        rc.subjname__c = 'K003';//科目名称
        rc.psncode__c = '002';//业务员编码
        rc.psnname__c = '刘三少';//业务员姓名
        rc.prodlinecode__c = '002';//产品线编码
        rc.prodlinename__c = '机器2';//产品线名称
        insert rc;
    }
}